package thread4;

/**
 * Created with IntelliJ IDEA
 * Description:
 * User:34398
 * Date:2024-07-02
 * Time:8:43
 */
public class demo4 {
    public static void main(String[] args) throws InterruptedException {

        //实例化一个Runnable接口，匿名内部类
        //创建一个Thread 把实例化的Runnable赋值
        //调用start
        Runnable runnable=new Runnable() {
            @Override
            public void run() {
                while(true){
                    System.out.println("创建了一个线程");
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        };

        Thread thread= new Thread(runnable);


       /* Thread thread=new Thread(new Runnable() {
            @Override
            public void run() {
                while(true){
                    System.out.println("在一个新的线程中");
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        });*/

        thread.start();
        while(true){
            System.out.println("主线程");
            Thread.sleep(1000);
        }


    }
}
